home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-portable.exe / quodlibet-3.3.0-portable / data / bin / ntpath.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  11KB  |  454 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''Common pathname manipulations, WindowsNT/95 version.
  5.  
  6. Instead of importing this module directly, import os and refer to this
  7. module as os.path.
  8. '''
  9. import os
  10. import sys
  11. import stat
  12. import genericpath
  13. import warnings
  14. from genericpath import *
  15. __all__ = [
  16.     'normcase',
  17.     'isabs',
  18.     'join',
  19.     'splitdrive',
  20.     'split',
  21.     'splitext',
  22.     'basename',
  23.     'dirname',
  24.     'commonprefix',
  25.     'getsize',
  26.     'getmtime',
  27.     'getatime',
  28.     'getctime',
  29.     'islink',
  30.     'exists',
  31.     'lexists',
  32.     'isdir',
  33.     'isfile',
  34.     'ismount',
  35.     'walk',
  36.     'expanduser',
  37.     'expandvars',
  38.     'normpath',
  39.     'abspath',
  40.     'splitunc',
  41.     'curdir',
  42.     'pardir',
  43.     'sep',
  44.     'pathsep',
  45.     'defpath',
  46.     'altsep',
  47.     'extsep',
  48.     'devnull',
  49.     'realpath',
  50.     'supports_unicode_filenames',
  51.     'relpath']
  52. curdir = '.'
  53. pardir = '..'
  54. extsep = '.'
  55. sep = '\\'
  56. pathsep = ';'
  57. altsep = '/'
  58. defpath = '.;C:\\bin'
  59. if 'ce' in sys.builtin_module_names:
  60.     defpath = '\\Windows'
  61. elif 'os2' in sys.builtin_module_names:
  62.     altsep = '/'
  63. devnull = 'nul'
  64.  
  65. def normcase(s):
  66.     '''Normalize case of pathname.
  67.  
  68.     Makes all characters lowercase and all slashes into backslashes.'''
  69.     return s.replace('/', '\\').lower()
  70.  
  71.  
  72. def isabs(s):
  73.     '''Test whether a path is absolute'''
  74.     s = splitdrive(s)[1]
  75.     if s != '':
  76.         pass
  77.     return s[:1] in '/\\'
  78.  
  79.  
  80. def join(a, *p):
  81.     '''Join two or more pathname components, inserting "\\" as needed.
  82.     If any component is an absolute path, all previous path components
  83.     will be discarded.'''
  84.     path = a
  85.     for b in p:
  86.         b_wins = 0
  87.         if path == '':
  88.             b_wins = 1
  89.         elif isabs(b):
  90.             if path[1:2] != ':' or b[1:2] == ':':
  91.                 b_wins = 1
  92.             elif (len(path) > 3 or len(path) == 3) and path[-1] not in '/\\':
  93.                 b_wins = 1
  94.             
  95.         if b_wins:
  96.             path = b
  97.             continue
  98.         if not len(path) > 0:
  99.             raise AssertionError
  100.         if None[-1] in '/\\':
  101.             if b and b[0] in '/\\':
  102.                 path += b[1:]
  103.             else:
  104.                 path += b
  105.         if path[-1] == ':':
  106.             path += b
  107.             continue
  108.         if b:
  109.             if b[0] in '/\\':
  110.                 path += b
  111.             else:
  112.                 path += '\\' + b
  113.         path += '\\'
  114.     
  115.     return path
  116.  
  117.  
  118. def splitdrive(p):
  119.     '''Split a pathname into drive and path specifiers. Returns a 2-tuple
  120. "(drive,path)";  either part may be empty'''
  121.     if p[1:2] == ':':
  122.         return (p[0:2], p[2:])
  123.     return (None, p)
  124.  
  125.  
  126. def splitunc(p):
  127.     """Split a pathname into UNC mount point and relative path specifiers.
  128.  
  129.     Return a 2-tuple (unc, rest); either part may be empty.
  130.     If unc is not empty, it has the form '//host/mount' (or similar
  131.     using backslashes).  unc+rest is always the input path.
  132.     Paths containing drive letters never have an UNC part.
  133.     """
  134.     if p[1:2] == ':':
  135.         return ('', p)
  136.     firstTwo = None[0:2]
  137.     if firstTwo == '//' or firstTwo == '\\\\':
  138.         normp = normcase(p)
  139.         index = normp.find('\\', 2)
  140.         if index == -1:
  141.             return ('', p)
  142.         index = None.find('\\', index + 1)
  143.         if index == -1:
  144.             index = len(p)
  145.         return (p[:index], p[index:])
  146.     return (None, p)
  147.  
  148.  
  149. def split(p):
  150.     '''Split a pathname.
  151.  
  152.     Return tuple (head, tail) where tail is everything after the final slash.
  153.     Either part may be empty.'''
  154.     (d, p) = splitdrive(p)
  155.     i = len(p)
  156.     while i and p[i - 1] not in '/\\':
  157.         i = i - 1
  158.     head = p[:i]
  159.     tail = p[i:]
  160.     head2 = head
  161.     while head2 and head2[-1] in '/\\':
  162.         head2 = head2[:-1]
  163.     if not head2:
  164.         pass
  165.     head = head
  166.     return (d + head, tail)
  167.  
  168.  
  169. def splitext(p):
  170.     return genericpath._splitext(p, sep, altsep, extsep)
  171.  
  172. splitext.__doc__ = genericpath._splitext.__doc__
  173.  
  174. def basename(p):
  175.     '''Returns the final component of a pathname'''
  176.     return split(p)[1]
  177.  
  178.  
  179. def dirname(p):
  180.     '''Returns the directory component of a pathname'''
  181.     return split(p)[0]
  182.  
  183.  
  184. def islink(path):
  185.     '''Test for symbolic link.
  186.     On WindowsNT/95 and OS/2 always returns false
  187.     '''
  188.     return False
  189.  
  190. lexists = exists
  191.  
  192. def ismount(path):
  193.     '''Test whether a path is a mount point (defined as root of drive)'''
  194.     (unc, rest) = splitunc(path)
  195.     if unc:
  196.         return rest in ('', '/', '\\')
  197.     p = None(path)[1]
  198.     if len(p) == 1:
  199.         pass
  200.     return p[0] in '/\\'
  201.  
  202.  
  203. def walk(top, func, arg):
  204.     """Directory tree walk with callback function.
  205.  
  206.     For each directory in the directory tree rooted at top (including top
  207.     itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
  208.     dirname is the name of the directory, and fnames a list of the names of
  209.     the files and subdirectories in dirname (excluding '.' and '..').  func
  210.     may modify the fnames list in-place (e.g. via del or slice assignment),
  211.     and walk will only recurse into the subdirectories whose names remain in
  212.     fnames; this can be used to implement a filter, or to impose a specific
  213.     order of visiting.  No semantics are defined for, or required of, arg,
  214.     beyond that arg is always passed to func.  It can be used, e.g., to pass
  215.     a filename pattern, or a mutable object designed to accumulate
  216.     statistics.  Passing None for arg is common."""
  217.     warnings.warnpy3k('In 3.x, os.path.walk is removed in favor of os.walk.', stacklevel = 2)
  218.     
  219.     try:
  220.         names = os.listdir(top)
  221.     except os.error:
  222.         return None
  223.  
  224.     func(arg, top, names)
  225.     for name in names:
  226.         name = join(top, name)
  227.         if isdir(name):
  228.             walk(name, func, arg)
  229.             continue
  230.  
  231.  
  232. def expanduser(path):
  233.     '''Expand ~ and ~user constructs.
  234.  
  235.     If user or $HOME is unknown, do nothing.'''
  236.     if path[:1] != '~':
  237.         return path
  238.     i = None
  239.     n = len(path)
  240.     while i < n and path[i] not in '/\\':
  241.         i = i + 1
  242.     if 'HOME' in os.environ:
  243.         userhome = os.environ['HOME']
  244.     elif 'USERPROFILE' in os.environ:
  245.         userhome = os.environ['USERPROFILE']
  246.     elif 'HOMEPATH' not in os.environ:
  247.         return path
  248.     
  249.     try:
  250.         drive = os.environ['HOMEDRIVE']
  251.     except KeyError:
  252.         drive = ''
  253.  
  254.     userhome = join(drive, os.environ['HOMEPATH'])
  255.     if i != 1:
  256.         userhome = join(dirname(userhome), path[1:i])
  257.     return userhome + path[i:]
  258.  
  259.  
  260. def expandvars(path):
  261.     '''Expand shell variables of the forms $var, ${var} and %var%.
  262.  
  263.     Unknown variables are left unchanged.'''
  264.     if '$' not in path and '%' not in path:
  265.         return path
  266.     import string as string
  267.     varchars = string.ascii_letters + string.digits + '_-'
  268.     res = ''
  269.     index = 0
  270.     pathlen = len(path)
  271.     while index < pathlen:
  272.         c = path[index]
  273.         if c == "'":
  274.             path = path[index + 1:]
  275.             pathlen = len(path)
  276.             
  277.             try:
  278.                 index = path.index("'")
  279.                 res = res + "'" + path[:index + 1]
  280.             except ValueError:
  281.                 res = res + path
  282.                 index = pathlen - 1
  283.             
  284.  
  285.         if c == '%':
  286.             if path[index + 1:index + 2] == '%':
  287.                 res = res + c
  288.                 index = index + 1
  289.             else:
  290.                 path = path[index + 1:]
  291.                 pathlen = len(path)
  292.                 
  293.                 try:
  294.                     index = path.index('%')
  295.                 except ValueError:
  296.                     res = res + '%' + path
  297.                     index = pathlen - 1
  298.  
  299.                 var = path[:index]
  300.                 if var in os.environ:
  301.                     res = res + os.environ[var]
  302.                 else:
  303.                     res = res + '%' + var + '%'
  304.         elif c == '$':
  305.             if path[index + 1:index + 2] == '$':
  306.                 res = res + c
  307.                 index = index + 1
  308.             elif path[index + 1:index + 2] == '{':
  309.                 path = path[index + 2:]
  310.                 pathlen = len(path)
  311.                 
  312.                 try:
  313.                     index = path.index('}')
  314.                     var = path[:index]
  315.                     if var in os.environ:
  316.                         res = res + os.environ[var]
  317.                     else:
  318.                         res = res + '${' + var + '}'
  319.                 except ValueError:
  320.                     res = res + '${' + path
  321.                     index = pathlen - 1
  322.                 
  323.  
  324.             var = ''
  325.             index = index + 1
  326.             c = path[index:index + 1]
  327.             while c != '' and c in varchars:
  328.                 var = var + c
  329.                 index = index + 1
  330.                 c = path[index:index + 1]
  331.             if var in os.environ:
  332.                 res = res + os.environ[var]
  333.             else:
  334.                 res = res + '$' + var
  335.             if c != '':
  336.                 index = index - 1
  337.             
  338.         else:
  339.             res = res + c
  340.         index = index + 1
  341.     return res
  342.  
  343.  
  344. def normpath(path):
  345.     '''Normalize path, eliminating double slashes, etc.'''
  346.     (backslash, dot) = (u'\\', u'.') if isinstance(path, unicode) else ('\\', '.')
  347.     if path.startswith(('\\\\.\\', '\\\\?\\')):
  348.         return path
  349.     path = None.replace('/', '\\')
  350.     (prefix, path) = splitdrive(path)
  351.     if prefix == '':
  352.         while path[:1] == '\\':
  353.             prefix = prefix + backslash
  354.             path = path[1:]
  355.     elif path.startswith('\\'):
  356.         prefix = prefix + backslash
  357.         path = path.lstrip('\\')
  358.     comps = path.split('\\')
  359.     i = 0
  360.     while i < len(comps):
  361.         if comps[i] in ('.', ''):
  362.             del comps[i]
  363.             continue
  364.         if comps[i] == '..':
  365.             if i > 0 and comps[i - 1] != '..':
  366.                 del comps[i - 1:i + 1]
  367.                 i -= 1
  368.             elif i == 0 and prefix.endswith('\\'):
  369.                 del comps[i]
  370.             else:
  371.                 i += 1
  372.         i += 1
  373.     if not prefix and not comps:
  374.         comps.append(dot)
  375.     return prefix + backslash.join(comps)
  376.  
  377.  
  378. try:
  379.     from nt import _getfullpathname
  380. except ImportError:
  381.     
  382.     def abspath(path):
  383.         '''Return the absolute version of a path.'''
  384.         if not isabs(path):
  385.             if isinstance(path, unicode):
  386.                 cwd = os.getcwdu()
  387.             else:
  388.                 cwd = os.getcwd()
  389.             path = join(cwd, path)
  390.         return normpath(path)
  391.  
  392.  
  393.  
  394. def abspath(path):
  395.     '''Return the absolute version of a path.'''
  396.     if path:
  397.         
  398.         try:
  399.             path = _getfullpathname(path)
  400.         except WindowsError:
  401.             pass
  402.         
  403.  
  404.     if isinstance(path, unicode):
  405.         path = os.getcwdu()
  406.     else:
  407.         path = os.getcwd()
  408.     return normpath(path)
  409.  
  410. realpath = abspath
  411. if hasattr(sys, 'getwindowsversion'):
  412.     pass
  413. supports_unicode_filenames = sys.getwindowsversion()[3] >= 2
  414.  
  415. def _abspath_split(path):
  416.     abs = abspath(normpath(path))
  417.     (prefix, rest) = splitunc(abs)
  418.     is_unc = bool(prefix)
  419.     if not is_unc:
  420.         (prefix, rest) = splitdrive(abs)
  421.     return (is_unc, prefix, [ x for x in rest.split(sep) if x ])
  422.  
  423.  
  424. def relpath(path, start = curdir):
  425.     '''Return a relative version of a path'''
  426.     if not path:
  427.         raise ValueError('no path specified')
  428.     (start_is_unc, start_prefix, start_list) = _abspath_split(start)
  429.     (path_is_unc, path_prefix, path_list) = _abspath_split(path)
  430.     if path_is_unc ^ start_is_unc:
  431.         raise ValueError('Cannot mix UNC and non-UNC paths (%s and %s)' % (path, start))
  432.     if path_prefix.lower() != start_prefix.lower():
  433.         if path_is_unc:
  434.             raise ValueError('path is on UNC root %s, start on UNC root %s' % (path_prefix, start_prefix))
  435.         raise ValueError('path is on drive %s, start on drive %s' % (path_prefix, start_prefix))
  436.     i = 0
  437.     for e1, e2 in zip(start_list, path_list):
  438.         if e1.lower() != e2.lower():
  439.             break
  440.         i += 1
  441.     
  442.     rel_list = [
  443.         pardir] * (len(start_list) - i) + path_list[i:]
  444.     if not rel_list:
  445.         return curdir
  446.     return None(*rel_list)
  447.  
  448.  
  449. try:
  450.     from nt import _isdir as isdir
  451. except ImportError:
  452.     pass
  453.  
  454.